package com.example.rabc.monitor;

import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;

/**
 * 存储处理器，将监控事件存储到数据库中
 */
@Component
public class StorageProcessor implements MonitorObserver {
    private final MonitorDataService monitorDataService;
    
    public StorageProcessor(MonitorDataService monitorDataService) {
        this.monitorDataService = monitorDataService;
    }

    /**
     * 处理监控事件，将其异步存储到数据库中
     * @param event 监控事件
     */
    @Override
    public void update(MonitorEvent event) {
        // 异步存储避免阻塞
        CompletableFuture.runAsync(() -> monitorDataService.saveMonitorData(event));
    }
    
    @Override
    public boolean supportsEventType(String eventType) {
        return true; // 存储所有类型的事件
    }
}